package com.compass.mobile.ui.dialog

import AppManager
import LogUtil
import UserInfoManager
import android.graphics.drawable.Drawable
import android.view.Gravity
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import androidx.fragment.app.FragmentActivity
import com.compass.mobile.R
import com.compass.mobile.callback.OnCustomButtonClick
import com.compass.mobile.databinding.DialogOrderDetailsBinding
import com.compass.mobile.framework.base.BaseDialog
import com.compass.mobile.framework.base.BaseDialogFragment
import com.compass.mobile.framework.constant.BACKSPACE_ACTION
import com.compass.mobile.framework.constant.BASE_PDF_FULL
import com.compass.mobile.framework.constant.CANCEL_ACTION
import com.compass.mobile.framework.constant.CLINICAL_RECEPTION
import com.compass.mobile.framework.constant.CREATED_SUCCESS_ACTION
import com.compass.mobile.framework.constant.DETAILS_ACTION
import com.compass.mobile.framework.constant.END_ACTION
import com.compass.mobile.framework.constant.INQUIRY_ACTION
import com.compass.mobile.framework.constant.INSPECT_ACTION
import com.compass.mobile.framework.constant.MY_ORDER
import com.compass.mobile.framework.constant.PRESCRIPTION_ACTION
import com.compass.mobile.framework.constant.REFERRAL_ACTION
import com.compass.mobile.framework.constant.YD_USER_TOKEN
import com.compass.mobile.framework.ext.gone
import com.compass.mobile.framework.ext.invisible
import com.compass.mobile.framework.ext.onClick
import com.compass.mobile.framework.ext.visible
import com.compass.mobile.framework.utils.BigDecimalUtils
import com.compass.mobile.framework.utils.CodeUtils.getCodeUrl
import com.compass.mobile.framework.utils.DateUtils
import com.compass.mobile.framework.utils.QRCodeDealUtils
import com.compass.mobile.framework.utils.TipsToast
import com.compass.mobile.models.InspectionDTO
import com.compass.mobile.models.OrderBean
import com.compass.mobile.models.PrescriptionDTO
import dp2px
import setUrlRound

/**
 * Description： 问诊单dialog
 * Date:2024/7/8 20:12
 */
class OrderCodeDialog {
    class Builder(
        activity: FragmentActivity,
        private var orderBean: OrderBean?,
        private var type: String?,
        private var action: String,
        private var customButtonClick: OnCustomButtonClick?
    ) :
        BaseDialogFragment.Builder<Builder>(activity) {
        private val mBinding: DialogOrderDetailsBinding =
            DialogOrderDetailsBinding.inflate(LayoutInflater.from(activity))
        private var codeUrl: String = MY_ORDER+ getCodeUrl()

        init {
            initView()
            setDoctor(orderBean)

            LogUtil
        }

        private fun initView() {
            setContentView(mBinding.root)
            setWidth((AppManager.getScreenHeightPx() * 0.9).toInt())
            setHeight(ViewGroup.LayoutParams.WRAP_CONTENT)
            setAnimStyle(BaseDialog.AnimStyle.DEFAULT)
            setGravity(Gravity.CENTER)
            setCancelable(true)
            mBinding.imgCode.setImageBitmap(
                QRCodeDealUtils.generateQRCodeWithoutMargin(
                    codeUrl,
                    dp2px(400f),
                    dp2px(400f)
                )
            )

        }

        private fun setDoctor(orderBean: OrderBean?) {
            orderBean?.let {
                mBinding.imgHead.setUrlRound(it.doctorAvatar, 5)
                mBinding.tvDoctorName.text = it.doctorName
                mBinding.tvPositionName.text = it.positionName
                mBinding.tvDepartments.text = it.departmentName
                mBinding.tvOrderId.text = "订单编号: ${it.id}"
                var visit = if (it.ifReturnVisit == "1") "是" else "否"
                var ifSanity = if (it.ifSanity == "1") "是" else "否"
                mBinding.ifReturnVisit.text = "是否复诊: $visit"
                mBinding.ifSanity.text = "是否神志清楚: $ifSanity"
                it.illnessDuration?.let { illnessDuration ->
                    mBinding.illnessDuration.text = "患病时长: $illnessDuration"
                } ?: kotlin.run {
                    mBinding.illnessDuration.text = "患病时长: 暂未填写"
                }
                it.lastDiagnosis?.let { lastDiagnosis ->
                    mBinding.lastDiagnosis.text = "上次诊断: $lastDiagnosis"
                } ?: kotlin.run {
                    mBinding.lastDiagnosis.text = "上次诊断: 暂未填写"
                }


                mBinding.tvStatus.text = UserInfoManager.getOrderTypeString(it.status)
                mBinding.tvPatientName.text = "患者姓名: ${it.patientName}"
                mBinding.tvDescription.text = "${it.diseaseDescriptionText}"
                mBinding.tvTime.text =
                    "创建时间: ${DateUtils.conversionTime(it.createTime, DateUtils.FORMAT_TWO)}"

                if (it.lastVisitDate != 0L)
                    mBinding.lastVisitDate.text =
                        "上次就诊: ${
                            DateUtils.conversionTime(
                                it.lastVisitDate,
                                DateUtils.FORMAT_FOUR
                            )
                        }"
                else
                    mBinding.lastVisitDate.text =
                        "上次就诊: 暂无"

                mBinding.tvEndTime.text =
                    "结束时间: ${getEndTime(it.consultationEndDate)}"
                it.proposalMsg?.let { proposalMsg ->
                    mBinding.tvProposalMsg.text = proposalMsg
                } ?: kotlin.run {
                    mBinding.tvProposalMsg.text = "医生暂未填写"
                }
                if (it.status == "0" || it.status == "1") {
                    mBinding.tvCancelInquire.visible()
                } else {
                    mBinding.tvCancelInquire.gone()
                }
                if (it.consultationCaseSignPdf.isNullOrEmpty()) {
                    mBinding.llCaseHistory.gone()
                } else {
                    mBinding.llCaseHistory.visible()
                    mBinding.caseHistoryCode.setImageBitmap(
                        QRCodeDealUtils.generateQRCodeWithoutMargin(
                            BASE_PDF_FULL + it.consultationCaseSignPdf,
                            dp2px(400f),
                            dp2px(400f)
                        )
                    )
                }


                setInspectionView(it.oiDTOList)
                setPrescriptionView(it.opDTOList)
                setTips()
                when (it.status) {
                    //0待支付 1 待接诊 2已接诊 3 待评价 4.已结束 -1 已取消 -2 已拒诊 -3 已退诊
                    "0" -> setStatusBar(
                        0,
                        it.status,
                        it.type,
                        !it.consultationCaseSignPdf.isNullOrEmpty()
                    )

                    "1" -> setStatusBar(
                        1,
                        it.status,
                        it.type,
                        !it.consultationCaseSignPdf.isNullOrEmpty()
                    )

                    "2" -> setStatusBar(
                        2,
                        it.status,
                        it.type,
                        !it.consultationCaseSignPdf.isNullOrEmpty()
                    )

                    "3" -> setStatusBar(
                        3,
                        it.status,
                        it.type,
                        !it.consultationCaseSignPdf.isNullOrEmpty()
                    )

                    "4" -> setStatusBar(
                        3,
                        it.status,
                        it.type,
                        !it.consultationCaseSignPdf.isNullOrEmpty()
                    )

                    else -> {
                        mBinding.llStatusBar.gone()
                    }
                }
            }

            mBinding.tvCancelInquire.onClick {

                customButtonClick?.onButtonCallBack(1, orderBean?.id)
            }


        }


        private var prescriptionIndex: Int = 0
        private fun setPrescriptionView(oiDTOList: MutableList<PrescriptionDTO>?) {
            if (oiDTOList.isNullOrEmpty()) {
                mBinding.emptyPrescription.visible()
                mBinding.llPrescriptionNumber.invisible()
                mBinding.tvRxData.invisible()
                mBinding.arrowLeft.invisible()
                mBinding.arrowRight.invisible()
                mBinding.tvRxStatus.invisible()
                mBinding.tvRxContent.invisible()
                mBinding.tvRxPrice.invisible()

            } else {
                setPrescription(
                    oiDTOList[prescriptionIndex],
                    (prescriptionIndex + 1).toString(),
                    oiDTOList.size
                )
                mBinding.arrowLeft.onClick {
                    if (prescriptionIndex > 0) {
                        prescriptionIndex--
                        setPrescription(
                            oiDTOList[prescriptionIndex],
                            (prescriptionIndex + 1).toString(),
                            oiDTOList.size
                        )
                    } else {
                        TipsToast
                    }

                }
                mBinding.arrowRight.onClick {
                    if (prescriptionIndex < oiDTOList.size - 1) {
                        prescriptionIndex++
                        setPrescription(
                            oiDTOList[prescriptionIndex],
                            (prescriptionIndex + 1).toString(),
                            oiDTOList.size
                        )
                    }
                }
            }
        }

        private fun setPrescription(inspectionDTO: PrescriptionDTO, index: String, size: Int) {
            mBinding.tvIndex.text = index
            mBinding.tvLength.text = "/${size}"
            mBinding.tvRxData.text = "开方日期 ${
                DateUtils.conversionTime(
                    inspectionDTO.createTime,
                    DateUtils.FORMAT_TWO
                )
            }"

            mBinding.tvRxStatus.text = inspectionDTO.statusName
            mBinding.tvRxContent.text = "处方药品：${inspectionDTO.drugNameStr}"

            mBinding.tvRxPrice.text = "合计金额：￥${BigDecimalUtils.divide(inspectionDTO.price)}"


        }


        private var inspectionIndex: Int = 0
        private fun setInspectionView(oiDTOList: MutableList<InspectionDTO>?) {
            if (oiDTOList.isNullOrEmpty()) {
                mBinding.emptyInspection.visible()
                mBinding.llNumbers.invisible()
                mBinding.arrowLeftIn.invisible()
                mBinding.arrowRightIn.invisible()
                mBinding.tvInData.invisible()
                mBinding.tvInContent.invisible()
                mBinding.tvInPrice.invisible()
                mBinding.tvInStatus.invisible()

            } else {
                setInspection(
                    oiDTOList[inspectionIndex],
                    (inspectionIndex + 1).toString(),
                    oiDTOList.size
                )
                mBinding.arrowLeftIn.onClick {
                    if (inspectionIndex > 0) {
                        inspectionIndex--
                        setInspection(
                            oiDTOList[inspectionIndex],
                            (inspectionIndex + 1).toString(),
                            oiDTOList.size
                        )
                    } else {
                        TipsToast
                    }

                }
                mBinding.arrowRightIn.onClick {
                    if (inspectionIndex < oiDTOList.size - 1) {
                        inspectionIndex++
                        setInspection(
                            oiDTOList[inspectionIndex],
                            (inspectionIndex + 1).toString(),
                            oiDTOList.size
                        )
                    }
                }
            }
        }

        private fun setInspection(inspectionDTO: InspectionDTO, index: String, size: Int) {
            mBinding.tvIndexIn.text = index
            mBinding.tvInStatus.text = UserInfoManager.getInspectionTypeString(inspectionDTO.status)
            mBinding.tvInContent.text = inspectionDTO.inspectionName
            mBinding.tvInPrice.text = "金额：￥${BigDecimalUtils.divide(inspectionDTO.price)}"
            mBinding.tvInData.text = "开具日期 ${
                DateUtils.conversionTime(
                    inspectionDTO.createTime,
                    DateUtils.FORMAT_TWO
                )
            }"
            mBinding.tvLengthIn.text = "/${size}"
        }


        private fun getEndTime(endTime: Long?): String {
            endTime?.let {

                return DateUtils.conversionTime(it, DateUtils.FORMAT_TWO)
            }
            return "--"
        }

        /***
         * 设置订单状态步骤
         */
        private fun setStatusBar(
            status: Int,
            orderStatus: String,
            type: String?,
            isShowQrCode: Boolean
        ) {
            LogUtil.d("status : ${status}，orderStatus :${orderStatus},type:${type},isShowQrCode:${isShowQrCode}", tag = "order_tag")
            //设置进度条
            if (status in 0..3) {
                mBinding.llStatusBar.visible()
                mBinding.refusalInfo.gone()

                val normalDrawable: Drawable =
                    ContextCompat.getDrawable(context, R.mipmap.item_status_normal)!!
                val selectDrawable: Drawable =
                    ContextCompat.getDrawable(context, R.mipmap.item_status_choose)!!

                val normalColor = ContextCompat.getColor(context, R.color.white)
                val selectColor = ContextCompat.getColor(context, R.color.text_ff)

                when (status) {
                    0 -> {
                        //待支付
                        mBinding.apply {
                            // 文字颜色
                            tvStatusNopay.setTextColor(
                                ContextCompat.getColor(
                                    context,
                                    R.color.text_ff
                                )
                            )
                            tvStatusWait.setTextColor(
                                ContextCompat.getColor(
                                    context,
                                    R.color.white
                                )
                            )
                            tvStatusReciver.setTextColor(
                                ContextCompat.getColor(
                                    context,
                                    R.color.white
                                )
                            )
                            tvStatusFinish.setTextColor(
                                ContextCompat.getColor(
                                    context,
                                    R.color.white
                                )
                            )
                            // 设置左侧图标
                            tvStatusNopay.setCompoundDrawablesWithIntrinsicBounds(
                                selectDrawable,
                                null,
                                null,
                                null
                            )
                            tvStatusWait.setCompoundDrawablesWithIntrinsicBounds(
                                normalDrawable,
                                null,
                                null,
                                null
                            )
                            tvStatusReciver.setCompoundDrawablesWithIntrinsicBounds(
                                normalDrawable,
                                null,
                                null,
                                null
                            )
                            tvStatusFinish.setCompoundDrawablesWithIntrinsicBounds(
                                normalDrawable,
                                null,
                                null,
                                null
                            )
                            // 线条颜色
                            lineNopay.setBackgroundColor(normalColor)
                            lineReciver.setBackgroundColor(normalColor)
                            lineFinish.setBackgroundColor(normalColor)

                            refusalInfo.gone()
                        }
                    }

                    1 -> {
                        //已支付、待接诊
                        mBinding.apply {
                            // 文字颜色
                            tvStatusNopay.setTextColor(
                                ContextCompat.getColor(
                                    context,
                                    R.color.text_ff
                                )
                            )
                            tvStatusWait.setTextColor(
                                ContextCompat.getColor(
                                    context,
                                    R.color.text_ff
                                )
                            )
                            tvStatusReciver.setTextColor(
                                ContextCompat.getColor(
                                    context,
                                    R.color.white
                                )
                            )
                            tvStatusFinish.setTextColor(
                                ContextCompat.getColor(
                                    context,
                                    R.color.white
                                )
                            )
                            // 设置左侧图标
                            tvStatusNopay.setCompoundDrawablesWithIntrinsicBounds(
                                selectDrawable,
                                null,
                                null,
                                null
                            )
                            tvStatusWait.setCompoundDrawablesWithIntrinsicBounds(
                                selectDrawable,
                                null,
                                null,
                                null
                            )
                            tvStatusReciver.setCompoundDrawablesWithIntrinsicBounds(
                                normalDrawable,
                                null,
                                null,
                                null
                            )
                            tvStatusFinish.setCompoundDrawablesWithIntrinsicBounds(
                                normalDrawable,
                                null,
                                null,
                                null
                            )
                            // 线条颜色
                            lineNopay.setBackgroundColor(selectColor)
                            lineReciver.setBackgroundColor(normalColor)
                            lineFinish.setBackgroundColor(normalColor)

                            refusalInfo.gone()
                        }
                    }

                    2 -> {
                        //已接诊
                        mBinding.apply {
                            // 文字颜色
                            tvStatusNopay.setTextColor(
                                ContextCompat.getColor(
                                    context,
                                    R.color.text_ff
                                )
                            )
                            tvStatusWait.setTextColor(
                                ContextCompat.getColor(
                                    context,
                                    R.color.text_ff
                                )
                            )
                            tvStatusReciver.setTextColor(
                                ContextCompat.getColor(
                                    context,
                                    R.color.text_ff
                                )
                            )
                            tvStatusFinish.setTextColor(
                                ContextCompat.getColor(
                                    context,
                                    R.color.white
                                )
                            )
                            // 设置左侧图标
                            tvStatusNopay.setCompoundDrawablesWithIntrinsicBounds(
                                selectDrawable,
                                null,
                                null,
                                null
                            )
                            tvStatusWait.setCompoundDrawablesWithIntrinsicBounds(
                                selectDrawable,
                                null,
                                null,
                                null
                            )
                            tvStatusReciver.setCompoundDrawablesWithIntrinsicBounds(
                                selectDrawable,
                                null,
                                null,
                                null
                            )
                            tvStatusFinish.setCompoundDrawablesWithIntrinsicBounds(
                                normalDrawable,
                                null,
                                null,
                                null
                            )
                            // 线条颜色
                            lineNopay.setBackgroundColor(selectColor)
                            lineReciver.setBackgroundColor(selectColor)
                            lineFinish.setBackgroundColor(normalColor)

                            refusalInfo.gone()
                        }
                    }

                    3 -> {
                        //问诊结束
                        mBinding.apply {
                            // 文字颜色
                            tvStatusNopay.setTextColor(
                                ContextCompat.getColor(
                                    context,
                                    R.color.text_ff
                                )
                            )
                            tvStatusWait.setTextColor(
                                ContextCompat.getColor(
                                    context,
                                    R.color.text_ff
                                )
                            )
                            tvStatusReciver.setTextColor(
                                ContextCompat.getColor(
                                    context,
                                    R.color.text_ff
                                )
                            )
                            tvStatusFinish.setTextColor(
                                ContextCompat.getColor(
                                    context,
                                    R.color.text_ff
                                )
                            )
                            // 设置左侧图标
                            tvStatusNopay.setCompoundDrawablesWithIntrinsicBounds(
                                selectDrawable,
                                null,
                                null,
                                null
                            )
                            tvStatusWait.setCompoundDrawablesWithIntrinsicBounds(
                                selectDrawable,
                                null,
                                null,
                                null
                            )
                            tvStatusReciver.setCompoundDrawablesWithIntrinsicBounds(
                                selectDrawable,
                                null,
                                null,
                                null
                            )
                            tvStatusFinish.setCompoundDrawablesWithIntrinsicBounds(
                                selectDrawable,
                                null,
                                null,
                                null
                            )
                            // 线条颜色
                            lineNopay.setBackgroundColor(selectColor)
                            lineReciver.setBackgroundColor(selectColor)
                            lineFinish.setBackgroundColor(selectColor)

                            refusalInfo.gone()
                        }
                    }
                }
            } else {
                mBinding.llStatusBar.gone()
                mBinding.refusalInfo.visible()
            }
            //设置右下角二维码
            when (type) {
                //图文问诊
                "1" -> {
                    //0待支付 1 待接诊 2已接诊 3 待评价 4.已结束 -1 已取消 -2 已拒诊 -3 已退诊
                    when (orderStatus) {
                        "0" -> {
                            mBinding.tvStatusText.text =
                                "你的问诊订单已创建，请使用移动爱家进行扫码支付"
                            mBinding.tvCodeTip.gone()
                        }
                        "1" -> {
                            mBinding.tvStatusText.text =
                                "使用移动爱家APP扫码在手机端进行问诊"
                            mBinding.tvCodeTip.gone()
                        }

                        "2" -> {
                            if (isShowQrCode) {
                                mBinding.apply {
                                    llCaseHistory.visible()
                                    tvCodeTip.visible()
                                    tvStatusText.gone()

                                    tvCodeTip.text = "使用移动爱家APP扫码在\n手机端进行问诊"
                                    tvCodeHistory.text = "使用移动爱家APP扫码\n查看患者病历"
                                }

                            } else {
                                mBinding.apply {
                                    tvStatusText.visible()
                                    tvStatusText.text = "使用移动爱家APP扫码在手机端进行问诊"
                                    tvCodeTip.gone()
                                    llCaseHistory.gone()
                                }

                            }
                        }

                        "3" -> {
                            if (isShowQrCode) {
                                mBinding.apply {
                                    llCaseHistory.visible()
                                    tvCodeTip.visible()
                                    tvStatusText.gone()

                                    tvCodeTip.text = "使用移动爱家APP扫码在\n手机端进行问诊"
                                    tvCodeHistory.text = "使用移动爱家APP扫码\n查看患者病历"
                                }

                            } else {
                                mBinding.apply {
                                    tvStatusText.text = "使用移动爱家APP扫码查看订单信息"
                                    tvStatusText.visible()
                                    tvCodeTip.gone()
                                    llCaseHistory.gone()
                                }

                            }
                        }

                        "4" -> {
                            if (isShowQrCode) {
                                mBinding.apply {
                                    llCaseHistory.visible()
                                    tvCodeTip.visible()
                                    tvStatusText.gone()

                                    tvCodeTip.text = "使用移动爱家APP扫码在\n手机端进行问诊"
                                    tvCodeHistory.text = "使用移动爱家APP扫码\n查看患者病历"
                                }

                            } else {
                                mBinding.apply {
                                    tvStatusText.text = "使用移动爱家APP扫码查看订单信息"
                                    tvStatusText.visible()
                                    tvCodeTip.gone()
                                    llCaseHistory.gone()
                                }
                            }
                        }

                        else -> {
                            mBinding.apply {
                                llStatusBar.gone()
                                refusalInfo.visible()
                                tvCodeTip.visible()
                            }
                        }
                    }

                }

                "2" -> {
                    //电话问诊
                    when (orderStatus) {
                        "0" -> {
                            mBinding.tvStatusText.text =
                                "你的问诊订单已创建，请使用移动爱家进行扫码支付"
                            mBinding.tvCodeTip.gone()
                        }
                        "1" -> {
                            mBinding.tvStatusText.text =
                                "使用移动爱家APP扫码在手机端进行问诊"
                            mBinding.tvCodeTip.gone()
                        }

                        "2" -> {

                            mBinding.apply {
                                tvStatusText.visible()
//                                tvStatusText.text = "使用移动爱家APP扫码查看订单信息"
                                tvStatusText.text = "医生将在15分钟内向你拨打电话,号码为029开头请注意接听"
                                tvCodeTip.gone()
                                llCaseHistory.gone()
                            }
                        }

                        "3" -> {
                            if (isShowQrCode) {
                                mBinding.apply {
                                    llCaseHistory.gone()
                                    tvCodeTip.visible()
                                    tvStatusText.gone()

                                    tvCodeTip.text = "使用移动爱家APP扫码查看订单信息"

                                }

                            } else {

                                mBinding.apply {
                                    tvStatusText.visible()
                                    tvStatusText.text = "使用移动爱家APP扫码查看订单信息"
                                    tvCodeTip.gone()
                                    llCaseHistory.gone()
                                }

                            }
                        }

                        "4" -> {
                            if (isShowQrCode) {
                                mBinding.apply {
                                    llCaseHistory.visible()
                                    tvCodeTip.visible()
                                    tvStatusText.gone()

                                    tvCodeTip.text = "使用移动爱家APP扫码在\n手机端进行问诊"
                                    tvCodeHistory.text = "使用移动爱家APP扫码\n查看患者病历"
                                }

                            } else {
                                mBinding.apply {
                                    tvStatusText.text = "使用移动爱家APP扫码查看订单信息"
                                    tvCodeTip.gone()
                                    llCaseHistory.gone()
                                }

                            }
                        }

                        else -> {
                            mBinding.apply {
                                llStatusBar.gone()
                                refusalInfo.visible()
                            }
                        }
                    }
                }

                "3" -> {
                    //视频问诊
                    when (orderStatus) {
                        "0" -> {
                            mBinding.tvStatusText.text =
                                "你的问诊订单已创建，请使用移动爱家进行扫码支付"
                            mBinding.tvCodeTip.gone()
                            mBinding.tvStatusText.visible()
                        }
                        "1" -> {
                            mBinding.tvStatusText.text =
                                "使用移动爱家APP扫码在手机端进行问诊"

                            mBinding.apply {
                                mBinding.tvStatusText.visible()
                                mBinding.tvCodeTip.gone()
                                tvCodeHistory.visible()
                            }
                        }

                        "2" -> {
                            mBinding.apply {
                                tvStatusText.text = "使用移动爱家APP扫码查看订单信息"
                                tvCodeTip.gone()
                                llCaseHistory.gone()
                            }
                        }

                        "3" -> {
                            if (isShowQrCode) {
                                mBinding.apply {
                                    llCaseHistory.gone()
                                    tvCodeTip.visible()
                                    tvStatusText.gone()

                                    tvCodeTip.text = "使用移动爱家APP扫码查看订单信息"
                                }

                            } else {
                                mBinding.apply {
                                    tvStatusText.text = "使用移动爱家APP扫码查看订单信息"
                                    tvCodeTip.gone()
                                    llCaseHistory.gone()
                                }

                            }
                        }

                        "4" -> {
                            if (isShowQrCode) {
                                mBinding.apply {
                                    llCaseHistory.visible()
                                    tvCodeTip.visible()
                                    tvStatusText.gone()

                                    tvCodeTip.text = "使用移动爱家APP扫码在手机端进行问诊"
                                    tvCodeHistory.text = "使用移动爱家APP扫码查看患者病历"
                                }

                            } else {
                                mBinding.apply {
                                    tvStatusText.text = "使用移动爱家APP扫码在手机端进行问诊"
                                    tvCodeTip.gone()
                                    llCaseHistory.gone()
                                }

                            }
                        }
                        else -> {
                            mBinding.apply {
                                llStatusBar.gone()
                                refusalInfo.visible()
                            }
                        }
                    }
                }
            }
        }

        private fun setTips() {
            when (action) {
                CREATED_SUCCESS_ACTION -> {
                    mBinding.refusalInfo.text =
                        "订单创建成功，请扫描右下方二维码支付并进行问诊"

                    mBinding.tvCodeTip.text =
                        "使用移动爱家APP扫一扫功能扫码支付\n支付完成后可进行问诊"
                }
                //处方
                PRESCRIPTION_ACTION -> {
                    mBinding.refusalInfo.text =
                        "医生向您开具的处方已审核通过"
                }

                DETAILS_ACTION -> {
                    mBinding.refusalInfo.text =
                        "问诊单详情"
                }

                INSPECT_ACTION -> {
                    mBinding.refusalInfo.text =
                        "医生向您开具了检验检查"
                }
                //接诊成功
                CLINICAL_RECEPTION -> {
                    mBinding.refusalInfo.text =
                        "医生已接诊"
                }

                //订单支付成功
                INQUIRY_ACTION -> {
                    //1-图文 2-语音 3-音视频
                    when (type) {
                        "1" -> {
                            mBinding.refusalInfo.text =
                                "订单支付成功！"
                        }

                        "2" -> {
                            mBinding.refusalInfo.text =
                                "订单支付成功！医生接诊后,将在15分钟内向您拨打电话，号码为029开头请注意接听!"
                        }

                        "3" -> {
                            mBinding.refusalInfo.text =
                                "订单支付成功！医生接诊后,将在15分钟内向您发起视频，请注意接听!"
                        }

                    }
                }

                //转诊action
                REFERRAL_ACTION -> {
                    mBinding.refusalInfo.text =
                        "医生已将您的问诊单转给其他医生!"
                }
                //问诊自动取消
                CANCEL_ACTION -> {
                    mBinding.refusalInfo.text =
                        "您的订单已取消！您可选择其他医生问诊!"
                }
                //退诊
                BACKSPACE_ACTION -> {
                    mBinding.refusalInfo.text =
                        "医生已将您的问诊单退诊!"
                }
                //结束问诊
                END_ACTION -> {
                    mBinding.refusalInfo.text =
                        "医生已结束了您的问诊！"
                }
            }
        }

        fun dismissDialog() {
            dismiss()
        }
    }


}
